/**
 * fshows.com
 * Copyright (C) 2013-2019 All Rights Reserved.
 */
package com.example.fardemo.jmh.counter.impl;

import com.example.fardemo.jmh.counter.ICounter;

import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

/**
 *
 * @author Liluqing
 * @version SignCounter.java, v 0.1 2019-05-06 18:16
 */
public class MyoneCounter implements ICounter {
    public volatile long num = 0;

    ExecutorService executor = Executors.newSingleThreadExecutor();

    Task task = new Task();

    @Override
    public void hit() {
        executor.execute(task);
    }

    @Override
    public long getRequestSum() {
        return num;
    }

    @Override
    public void close() {
        executor.shutdown();
    }

    class Task implements Runnable {

        @Override
        public void run() {
            num++;
        }
    }
}